home *** CD-ROM | disk | FTP | other *** search
- /*
- IC File Map What.c
-
- */
-
- #include <Icons.h>
- #include <ToolUtils.h>
- #include <LowMem.h>
-
- #include "IC Window Globals.h"
- #include "IC StrH.h"
- #include "IC Types.h"
- #include "IC Keys.h"
- #include "IC API.h"
- #include "IC Subs.h"
- #include "IC Dialogs.h"
- #include "IC Misc Subs.h"
- #include "IC Document.h"
- #include "IC Globals.h"
- #include "IC IconSuites.h"
- #include "IC StandardFile.h"
- #include "IC Movable Modal.h"
- #include "IC Windows.h"
-
- #include "IC File Map What.h"
-
- #include "SpinLib.h"
-
- void DimButtons(WindowType wt){
- ListHandle lh=(ListHandle)WindowInfo[wt].items[ditList]->spare_data;
- DialogPtr dlg=WindowInfo[wt].window;
- Boolean have_selection=(SelectedLine(lh)!=-1);
- Boolean unlok=!IsLocked(wt,ditList);
-
- SetDCtlEnable(dlg,ditAdd,unlok);
- SetDCtlEnable(dlg,ditDelete,have_selection&&unlok);
- SetDCtlEnable(dlg,ditChange,have_selection&&unlok);
- SetDCtlEnable(dlg,ditDefaults,unlok);
-
- OutlineDefault1(dlg,ditMainUserItem);
- }
-
- void LDClose(void){
-
- }
-
- void LDDraw(Handle entries,Boolean select,Rect* r,Cell the_cell,short offset,short datalen,ListHandle lh){
- ICMapEntry entry;
- OSErr err;
- long junkpos;
- Handle suite;
- short cur_x,top,transfer=ttNone;
- Rect tmprect;
- FontInfo sys_font_info,appl_font_info;
- RgnHandle rgn=(RgnHandle)0,rgn2;
- Str255 astr,bstr;
-
- if (datalen==0){
- err=ICMapErr(ICGetIndMapEntry(GetInstance(),entries,the_cell.v+1,&junkpos,&entry));
- if (err==noErr){
- EraseRect(r);
- cur_x=0;
- rgn=NewRgn();
- if (System7){
- tmprect.top=r->top;
- tmprect.left=r->left;
- tmprect.bottom=tmprect.top+32;
- tmprect.right=tmprect.left+32;
-
- if (kCellHeight!=32)
- OffsetRect(&tmprect,(kCellHeight-32)/2,(kCellHeight-32)/2);
-
- GetDTDBIconSuiteCached(entry.file_type,entry.file_creator,&suite);
- if (suite!=(Handle)0){
- if (select)
- transfer=ttSelected;
- err=PlotIconSuite(&tmprect,atNone,transfer,suite);
- IconSuiteToRgn(rgn,&tmprect,atNone,suite);
- }
- cur_x+=kCellHeight;
- }
- cur_x+=2;
-
- TextFont(systemFont);
- GetFontInfo(&sys_font_info);
- TextFont(applFont);
- GetFontInfo(&appl_font_info);
-
- top=(kCellHeight-(sys_font_info.ascent+sys_font_info.descent+appl_font_info.ascent+appl_font_info.descent))/2;
- TextFont(systemFont);
-
- MoveTo(r->left+cur_x,r->top+top+sys_font_info.ascent);
- DrawString(SetPString(astr,3,entry.creator_app_name,GetAString(bstr,128,5),entry.entry_name));
-
- TextFont(applFont);
- MoveTo(r->left+cur_x,r->top+top+sys_font_info.ascent+sys_font_info.descent+appl_font_info.ascent);
- DrawString(entry.extension);
-
- if (select){
- rgn2=NewRgn();
- RectRgn(rgn2,r);
-
- if (Has_ColorQD){
- unsigned char hl;
-
- hl=LMGetHiliteMode();
- BitClr((Ptr)&hl,pHiliteBit);
- LMSetHiliteMode(hl);
- }
-
- XorRgn(rgn,rgn2,rgn2);
- InvertRgn(rgn2);
- DisposeRgn(rgn2);
- }
- if (rgn!=(RgnHandle)0)
- DisposeRgn(rgn);
- }
- }
- }
-
-
- pascal void MyLDEF(short message,Boolean select,Rect* r,Cell the_cell,short offset,short datalen,ListHandle lh){
- Handle entries;
-
- SetPort((*lh)->port);
- entries=(Handle)WindowInfo[GetWindowType((*lh)->port)].items[ditList]->data;
-
- if (message==lCloseMsg)
- LDClose();
- else if ((message==lDrawMsg)||(message==lHiliteMsg))
- LDDraw(entries,select,r,the_cell,offset,datalen,lh);
- }
-
- pascal void FileMapUserItemUpdate(DialogPtr dlg,short item){
- Rect list_rect;
-
- GetDItemRect(dlg,item,&list_rect);
- PenNormal();
- InsetRect(&list_rect,-1,-1);
- FrameRect(&list_rect);
- LUpdate(dlg->visRgn,(ListHandle)WindowInfo[GetWindowType(dlg)].items[item]->spare_data);
- }
-
- OSErr WhatOpenFileMap(WindowType wt,short item){
- DialogPtr dlg=WindowInfo[wt].window;
- Handle entries=(Handle)0;
- long attr;
- OSErr err=noErr;
- long count;
- Rect list_rect,data_rect;
- Point cell_size;
- ListHandle lh;
-
- WindowInfo[wt].items[item]->spare_data=(Ptr)0;
- WindowInfo[wt].items[item]->data=(Ptr)0;
-
- SetDItemHandle(dlg,item,(Handle)gFileMapUserItemUpdate);
- if (ICMapErr(ICGetPrefHandle(GetInstance(),WindowInfo[wt].items[item]->key,&attr,&entries))!=noErr){
- entries=NewHandle(0);
- if (entries==(Handle)0)
- err=memFullErr;
- }
- ProcessAttributes(wt,item,attr);
-
- if (err==noErr){
- if (ICMapErr(ICCountMapEntries(GetInstance(),entries,&count))!=noErr)
- count=0;
- WindowInfo[wt].items[item]->data=(Ptr)entries;
- GetDItemRect(dlg,item,&list_rect);
- list_rect.right-=15;
- SetRect(&data_rect,0,0,1,count);
- SetPt(&cell_size,list_rect.right-list_rect.left,kCellHeight);
- lh=LNew(&list_rect,&data_rect,cell_size,128,dlg,true,false,false,true);
- if (lh==(ListHandle)0)
- err=memFullErr;
- }
-
- if (err==noErr){
- (*lh)->refCon=(long)gFileListLDEF;
- (*lh)->selFlags=lOnlyOne;
- WindowInfo[wt].items[item]->spare_data=(Ptr)lh;
- DimButtons(wt);
- SetUpDefaultOutline(dlg,ditChange,ditMainUserItem);
- WindowInfo[wt].selected_item=ditList;
- }
-
- return err;
- }
-
- void SetRadio(DialogPtr modal,short value){
- SetDCtlBoolean(modal,ditAsciiRadio,value==ditAsciiRadio);
- SetDCtlBoolean(modal,ditBinaryRadio,value==ditBinaryRadio);
- SetDCtlBoolean(modal,ditMacintoshRadio,value==ditMacintoshRadio);
- }
-
- pascal Boolean AddChangeFilter(DialogPtr dlg,EventRecord* event,short* item){
- Boolean res;
- char ch;
-
- res=CancelModalFilter(dlg,event,item);
- if (!res){
- if ((event->what==keyDown)&&(event->modifiers&cmdKey)){
- ch=event->message&charCodeMask;
- if ((ch>='1')&&(ch<='3'))
- SetRadio(dlg,ch-'1'+ditAsciiRadio);
- }
- }
-
- return res;
- }
-
- OSErr GetMapEntriesResource(Handle* entries){
- OSErr err;
- short orf=CurResFile();
-
- UseResFile(app_resfile);
- *entries=Get1NamedResource('Pref',kICMapping);
- MoveHHi(*entries);
- UseResFile(orf);
-
- err=ResError();
- if ((*entries==(Handle)0)&&(err==noErr))
- err=resNotFound;
-
- return err;
- }
-
- StringPtr MapOSType(OSType ot,StringPtr str){
- if (ot==(OSType)0)
- str[0]=0;
- else
- OSTypeToString(ot,str);
-
- return str;
- }
-
- OSType MapStr(StringPtr s){
- OSType typ;
- Str31 tstr;
-
- Concat(s,1,"\p "); // add 4 spaces
- TPCopy(tstr,s,1,4);
- StringToOSType(tstr,&typ);
- return typ;
- }
-
-
- void DoChooseExample(DialogPtr modal){
- FInfo info;
- OSErr err;
- FSSpec fs,app_fss;
- Str255 tstr;
-
- err=ICStandardGetFile((OSType)0,&fs,&info);
- DisplayError(acGetExample,err);
- if (err==noErr){
- SetItemText(modal,ditType,MapOSType(info.fdType,tstr));
- SetItemText(modal,ditCreator,MapOSType(info.fdCreator,tstr));
- err=MyGetAPPL(info.fdCreator,&app_fss);
- if (err==noErr)
- SetItemText(modal,ditApplicationName,app_fss.name);
- else
- SetItemText(modal,ditApplicationName,"\p");
- }
- }
-
- Boolean ChoosePost(ICMapEntry* entry){
- FInfo info;
- OSErr err;
- FSSpec fs;
-
- err=ICStandardGetFile('APPL',&fs,&info);
- DisplayError(acGetExample,err);
- if (err==noErr){
- entry->post_creator=info.fdCreator;
- SetPString(entry->post_app_name,1,fs.name);
- }
- return err==noErr;
- }
-
- void SetPostInfo(ICMapEntry* entry,DialogPtr modal){
- Str255 tstr,s1,s2;
-
- if (entry->post_creator!=(OSType)0){
- SetPString(tstr,3,GetIndStr(128,24,s1),entry->post_app_name,GetIndStr(128,25,s2));
- SetDCtlTitle(modal,ditPostButton,tstr);
- SetItemText(modal,ditPostCreator,MapOSType(entry->post_creator,tstr));
- } else {
- SetDCtlTitle(modal,ditPostButton,SetPString(tstr,1,GetIndStr(128,23,s1)));
- SetItemText(modal,ditPostCreator,"\p");
- }
- SetDCtlBoolean(modal,ditPost,(entry->flags&(1<<ICmap_post_bit)));
- }
-
- void SetAllTheStuff(ICMapEntry* entry,DialogPtr modal){
- Boolean bin=BitTst(&entry->flags,ICmap_binary_bit);
- Boolean res=BitTst(&entry->flags,ICmap_resource_fork_bit);
- Str255 str;
-
- SetItemText(modal,ditEntryName,entry->entry_name);
- SetItemText(modal,ditExtension,entry->extension);
- SetItemText(modal,ditMIMEType,entry->MIME_type);
-
- SetDCtlBoolean(modal,ditAsciiRadio,!bin);
- SetDCtlBoolean(modal,ditBinaryRadio,bin&&!res);
- SetDCtlBoolean(modal,ditMacintoshRadio,bin&&res);
-
- SetDCtlBoolean(modal,ditNotForIncoming,BitTst(&entry->flags,ICmap_not_incoming_bit));
- SetDCtlBoolean(modal,ditNotForOutgoing,BitTst(&entry->flags,ICmap_not_outgoing_bit));
-
- SetItemText(modal,ditType,MapOSType(entry->file_type,str));
- SetItemText(modal,ditCreator,MapOSType(entry->file_creator,str));
-
- SetItemText(modal,ditApplicationName,entry->creator_app_name);
-
- SetPostInfo(entry,modal);
-
- SelectDialogItemText(modal,ditEntryName,0,32767);
- }
-
- void SetAddEditDefaults(ICMapEntry* entry,DialogPtr modal){
- OSErr err;
- Str255 ext;
- Handle entries;
- ICMapEntry new_entry;
- short a;
-
- GetItemText(modal,ditExtension,ext);
- err=GetMapEntriesResource(&entries);
- if (err==noErr){
- err=ICMapErr(ICMapEntriesFilename(GetInstance(),entries,ext,&new_entry));
- ReleaseResource(entries);
- }
-
- if (err==noErr){
- BlockMoveData((Ptr)&new_entry,(Ptr)entry,sizeof(ICMapEntry));
- SetAllTheStuff(entry,modal);
- }
-
- if (err==icPrefNotFoundErr){
- ParamText("\p",ext,"\p","\p");
- StopAlert(166,gOKModalFilter);
- } else
- DisplayError(acSetDefaults,err);
- }
-
-
- OSErr DoDialog(ICMapEntry* entry){
- DialogPtr modal;
- OSErr err=noErr;
- short item;
- long flags;
- Str255 tmpstr;
- Ptr saved_state;
- Boolean dummy;
-
- modal=GetNewDialog(700,(Ptr)0,(WindowPtr)-1);
-
- if (modal==(DialogPtr)0)
- err=memFullErr;
-
- if (err==noErr){
- SetUpDefaultOutline(modal,ditOK,ditEditorUserItem);
- SetAllTheStuff(entry,modal);
-
- ShowWindow(modal);
- DisableMenuBar(&saved_state,-1);
- InitCursor();
-
- do {
- MovableModalDialog(gAddChangeFilter,&item);
-
- switch (item){
- case ditAsciiRadio: case ditBinaryRadio: case ditMacintoshRadio:
- SetRadio(modal,item);
- break;
- case ditNotForIncoming: case ditNotForOutgoing:
- ToggleDCtlBoolean(modal,item);
- break;
- case ditChooseExample:
- DoChooseExample(modal);
- break;
- case ditPost:
- if (!(entry->flags&(1<<ICmap_post_bit))){
- if (entry->post_creator==(OSType)0){
- if (entry->file_creator!=(OSType)0){
- entry->post_creator=entry->file_creator;
- SetPString(entry->post_app_name,1,entry->creator_app_name);
- } else {
- ChoosePost(entry);
- }
- }
- if (entry->post_creator!=(OSType)0) // set the post bit
- entry->flags |= (1<<ICmap_post_bit);
- } else {
- // turn off the bit
- entry->flags &= (~(1<<ICmap_post_bit));
- }
- SetPostInfo(entry,modal);
- break;
- case ditPostButton:
- if (ChoosePost(entry))
- entry->flags|=(1<<ICmap_post_bit);
- SetPostInfo(entry,modal);
- break;
- case ditAddEditDefaults:
- SetAddEditDefaults(entry,modal);
- break;
- }
- } while ((item!=ditOK)&&(item!=ditCancel));
-
- if (item==ditOK){
- long mask;
-
- GetItemText(modal,ditEntryName,entry->entry_name);
- GetItemText(modal,ditExtension,entry->extension);
- GetItemText(modal,ditMIMEType,entry->MIME_type);
-
- mask=0L;
- mask |= ICmap_binary_mask | ICmap_data_fork_mask | ICmap_resource_fork_mask;
- mask |= ICmap_not_incoming_mask | ICmap_not_outgoing_mask;
-
- flags=entry->flags & (~mask); // clear the lower bits from the flag
- flags |= ICmap_data_fork_mask;
-
- if (!GetDCtlBoolean(modal,ditAsciiRadio))
- flags |= ICmap_binary_mask;
- if (GetDCtlBoolean(modal,ditMacintoshRadio))
- flags |= ICmap_resource_fork_mask;
- if (GetDCtlBoolean(modal,ditNotForIncoming))
- flags |= ICmap_not_incoming_mask;
- if (GetDCtlBoolean(modal,ditNotForOutgoing))
- flags |= ICmap_not_outgoing_mask;
-
- entry->flags=flags;
-
- GetItemText(modal,ditType,tmpstr);
- entry->file_type=MapStr(tmpstr);
-
- GetItemText(modal,ditCreator,tmpstr);
- entry->file_creator=MapStr(tmpstr);
-
- GetItemText(modal,ditApplicationName,entry->creator_app_name);
- } else
- err=userCanceledErr;
- }
-
- if (modal!=(DialogPtr)0){
- ReEnableMenuBar(&saved_state);
- DisposeDialog(modal);
- }
-
- return err;
- }
-
- OSErr DoAddChange(short selection,ICMapEntry* entry,Handle entries,ListHandle lh){
- OSErr err=noErr;
- long pos;
-
- if (selection==-1){
- entry->version=0;
- entry->file_creator=entry->post_creator=entry->file_type=(OSType)0;
- entry->flags=0L;
- entry->extension[0]=entry->creator_app_name[0]=entry->post_app_name[0]=0;
- entry->MIME_type[0]=entry->entry_name[0]=0;
- } else
- err=ICMapErr(ICGetIndMapEntry(GetInstance(),entries,selection+1,&pos,entry));
-
- if (err==noErr)
- err=DoDialog(entry);
-
- if (err==noErr){
- if (selection==-1){
- err=ICMapErr(ICAddMapEntry(GetInstance(),entries,entry));
- if (err==noErr)
- LAddRow(1,32767,lh);
- } else
- err=ICMapErr(ICSetMapEntry(GetInstance(),entries,pos,entry));
- }
-
- return err;
- }
-
- OSErr SetEntriesHandle(WindowType wt,Handle entries){
- OSErr err;
- Handle tmph;
- long count;
- ListHandle list=(ListHandle)WindowInfo[wt].items[ditList]->spare_data;
- WindowPtr window;
- short row;
-
- err=ICMapErr(ICCountMapEntries(GetInstance(),entries,&count));
-
- if (err==noErr){
- window=GetWindowPtr(wt);
- LDelRow((*list)->dataBounds.bottom+10,0,list);
- tmph=entries;
- entries=(Handle)WindowInfo[wt].items[ditList]->data;
- WindowInfo[wt].items[ditList]->data=(Ptr)tmph;
- row=LAddRow(count,0,list);
- }
-
- DisposeHandle(entries);
-
- return err;
- }
-
- /*
- The following quicksort implementation is based loosely upon Symantec's qsort ANSI routine.
- In fact, it is their routine except the comparison function is hard coded and the need to use globals
- has been removed.
- */
- long PartitionSmall(SmallArrayHandle small,register long p,register long r);
- long PartitionSmall(SmallArrayHandle small,register long p,register long r){
- register long mid;
- register long j;
- SmallRecordPtr swap;
-
- mid=(p+r)/2;
- p--;
- j=r+1;
-
- while (1){
- while (IUCompString((*small)[--j]->key,(*small)[mid]->key)>0)
- ;
- while (IUCompString((*small)[++p]->key,(*small)[mid]->key)<0)
- ;
-
- if (p<j){
- if (p>mid)
- mid=p;
- if (j<mid)
- mid=j;
-
- // switch the pointers in the array
- swap=(*small)[p];
- (*small)[p]=(*small)[j];
- (*small)[j]=swap;
-
- if (p==mid){
- mid=j++;
- } else if (j==mid){
- mid=p--;
- }
- } else {
- if (mid==r)
- return (mid-1);
- else
- return mid;
- }
- }
- }
-
- void QuickSortSmall(register SmallArrayHandle small,register long first,register long last){
- long q;
-
- while (first<last){
- q=PartitionSmall(small,first,last);
- QuickSortSmall(small,first,q);
- first=q+1;
- }
- }
-
- void SmallSort(SmallArrayHandle small,long count){
-
- if (count<1)
- return; // no elements to sort
-
- QuickSortSmall(small,0,count-1);
- }
-
- /*
- DoSort - Sort the list based on extension, creator, or name.
-
- Unlike the pascal version, I am using an array of pointers to control the sorting.
- Hopefully this would result in a traumatic speed increase when sorting a large list of items,
- assuming I got the translation correct. (speed increase a result of swapping pointers instead of elements).
-
- I also removed the set to the watch cursor and replaced with spinning beachball cursor library.
- */
- void DoSort(WindowType wt,short item){
- Handle entries=(Handle)WindowInfo[wt].items[ditList]->data,sorted_entries=NewHandle(0);
- SmallArrayHandle small;
- SmallRecord** arr;
- long count,pos,i;
- ICMapEntry entry;
- // CursHandle curs=GetCursor(watchCursor);
- ICInstance inst=GetInstance();
- OSErr err=ICMapErr(ICCountMapEntries(inst,entries,&count));
- StringPtr sp;
-
- // SetCursor(*curs);
-
- SpinStart(kForwardDirection);
-
- PrepMem(); // purge & compact memory
-
- if (err==noErr){
- arr=(SmallRecord**)NewHandle(sizeof(SmallRecord)*(count+2));
- err=MemError();
- if (err==noErr){
- small=(SmallArrayHandle)NewHandle(sizeof(SmallArray)*count);
- err=MemError();
- if (err==noErr){
- pos=0L;
- for (i=0;i<count;i++){
- (*small)[i]=&((*arr)[i]);
- err=ICMapErr(ICGetMapEntry(inst,entries,pos,&entry));
- if (err!=noErr){
- err=-8002;
- break;
- }
- (*small)[i]->position=i+1;
-
- if (item==ditSortExtension)
- sp=entry.extension;
- else if (item==ditSortApplication)
- sp=entry.creator_app_name;
- else if (item==ditSortName)
- sp=entry.entry_name;
- else
- sp=(StringPtr)0;
-
- if (sp!=(StringPtr)0)
- TPCopy((*small)[i]->key,sp,1,31);
-
- pos+=entry.total_length;
- }
- if (err==noErr){
- SmallSort(small,count);
- HLock(entries);
-
- for (i=0;i<count;i++){
- err=ICMapErr(ICGetIndMapEntry(inst,entries,(*small)[i]->position,&pos,&entry));
- if (err==noErr)
- err=PtrAndHand((Ptr)(((long)(*entries))+pos),sorted_entries,entry.total_length);
- if (err!=noErr)
- break;
- }
- if (err)
- err=-8003;
- HUnlock(entries);
- }
- if (err==noErr){
- err=SetEntriesHandle(wt,sorted_entries);
- if (err)
- err=-8004;
- sorted_entries=(Handle)0;
- }
- DisposeHandle((Handle)small);
- small=(SmallArrayHandle)0;
- } else err=-8001;
- DisposeHandle((Handle)arr);
- arr=(SmallRecord**)0;
- } else err=-8000;
- }
-
- if (sorted_entries!=(Handle)0)
- DisposeHandle(sorted_entries);
-
- // InitCursor();
- InvalidateAbout();
- SpinStop();
-
- DisplayError(acSort,err);
- }
-
- void DoSetDefaults(WindowType wt){
- OSErr err;
- Handle entries;
-
- if (CautionAlert(165,gCancelModalFilter)==1){
- err=GetMapEntriesResource(&entries);
- if (err==noErr){
- DetachResource(entries);
- err=SetEntriesHandle(wt,entries);
- }
- DisplayError(acSetDefaults,err);
- if (err==noErr)
- DirtyDocument();
- }
- }
-
- OSErr WhatClickFileMap(WindowType wt,short item,EventRecord* er){
- ListHandle lh=(ListHandle)WindowInfo[wt].items[ditList]->spare_data;
- ICMapEntry entry;
- Handle entries=(Handle)WindowInfo[wt].items[ditList]->data;
- short selection;
- OSErr err=(OSErr)1;
- long pos;
-
- GlobalToLocal(&(er->where));
- selection=SelectedLine(lh);
-
- switch (item){
- case ditAdd:
- err=DoAddChange(-1,&entry,entries,lh);
- break;
- case ditChange:
- err=DoAddChange(selection,&entry,entries,lh);
- break;
- case ditDelete:
- if (selection!=-1){
- err=ICMapErr(ICGetIndMapEntry(GetInstance(),entries,selection+1,&pos,&entry));
- if (err==noErr)
- err=ICMapErr(ICDeleteMapEntry(GetInstance(),entries,pos));
- if (err==noErr)
- LDelRow(1,selection,lh);
- }
- break;
- case ditList:
- if (LClick(er->where,0,lh)){
- if (IsLocked(wt,item)){
- LockedAlert(wt,item);
- err=userCanceledErr;
- } else {
- FlashItem(WindowInfo[wt].window,ditChange);
- err=DoAddChange(SelectedLine(lh),&entry,entries,lh); // selection may have been changed by LClick
- }
- }
- break;
- case ditSortExtension:
- case ditSortApplication:
- case ditSortName:
- DoSort(wt,item);
- break;
- case ditDefaults:
- DoSetDefaults(wt);
- break;
- }
-
- if (err==noErr)
- DirtyDocument();
-
- if (err==(OSErr)1)
- err=noErr;
-
- DimButtons(wt);
-
- return err;
- }
-
- OSErr WhatFlushFileMap(WindowType wt,short item){
- OSErr err=noErr;
-
- if (!IsLocked(wt,item))
- err=ICMapErr(ICSetPrefHandle(GetInstance(),WindowInfo[wt].items[item]->key,ICattr_no_change,(Handle)WindowInfo[wt].items[item]->data));
-
- return err;
- }
-
- OSErr WhatCloseFileMap(WindowType wt,short item){
- LDispose((ListHandle)WindowInfo[wt].items[item]->spare_data);
- DisposeHandle((Handle)WindowInfo[wt].items[item]->data);
- return noErr;
- }
-
- OSErr WhatActivateFileMap(WindowType wt,short item,Boolean activate){
- LActivate(activate,(ListHandle)WindowInfo[wt].items[item]->spare_data);
- return noErr;
- }
-
- pascal StringPtr GetFileMapEntryName(ListHandle list,Cell c,StringPtr str){
- ICMapEntry entry;
- OSErr err;
- long junk;
- Handle entries;
-
- str[0]=0;
- entries=(Handle)WindowInfo[GetWindowType((*list)->port)].items[ditList]->data;
- err=ICMapErr(ICGetIndMapEntry(GetInstance(),entries,c.v+1,&junk,&entry));
- if (err==noErr)
- SetPString(str,1,entry.extension);
- return str;
- }
-
- OSErr WhatKeyFileMap(WindowType wt,short item,EventRecord* er){
- char ch;
- ICMapEntry entry;
- ListHandle lh=(ListHandle)WindowInfo[wt].items[ditList]->spare_data;
- OSErr err=noErr;
-
- if ((er->what==keyDown)||(er->what==autoKey)){
- ch=er->message&0x00ff;
- if ((ch==crChar)||(ch==enterChar)){
- if (GetDCtlEnable(WindowInfo[wt].window,ditChange)){
- FlashItem(WindowInfo[wt].window,ditChange);
- err=DoAddChange(SelectedLine(lh),&entry,(Handle)WindowInfo[wt].items[ditList]->data,lh);
- if (err==noErr)
- DirtyDocument();
- }
- } else {
- DoListKey(lh,er,gGetFileMapEntryName);
- DimButtons(wt);
- }
- }
- return err;
- }
-
- OSErr WhatCursorFileMap(WindowType wt,short item,Point pt,short cursid){
- Rect r;
- CursHandle curs=GetCursor(cursid);
-
- GetDItemRect(WindowInfo[wt].window,item,&r);
- InsetRect(&r,15,0);
- if (PtInRect(pt,&r))
- SetCursor(*curs);
- else
- InitCursor();
-
- return noErr;
- }
-
- void MappingSetSelection(const StringPtr key){
- OSErr err;
- WindowPtr window=GetWindowPtr(WT_FileMapping);
- long count,i,pos;
- Handle entries;
- ICMapEntry entry;
- ListHandle list;
- ICInstance inst=GetInstance();
-
- if (window!=(WindowPtr)0){
- entries=(Handle)WindowInfo[WT_FileMapping].items[ditList]->data;
- list=(ListHandle)WindowInfo[WT_FileMapping].items[ditList]->spare_data;
- err=ICMapErr(ICCountMapEntries(inst,entries,&count));
- if (err==noErr){
- pos=0L;
- for (i=1;i<=count;i++){
- err=ICMapErr(ICGetMapEntry(inst,entries,pos,&entry));
- if (err!=noErr)
- break;
- pos+=entry.total_length;
- if (IUEqualString(entry.extension,key)==0){
- LSetSingleSelection(list,i-1);
- DimButtons(WT_FileMapping);
- if (GetDCtlEnable(window,ditChange))
- err=DoAddChange(i-1,&entry,entries,list);
- }
- }
- }
- }
- }
-
-
-
-
-